import http from '@/utils/http';


export function getOutboundList(params) {
  return http.get('/inventory/outbound/orders', { params });
}


export function getOutboundDetail(id) {
  return http.get(`/inventory/outbound/orders/${id}`);
}


export function createOutbound(data) {
  return http.post('/inventory/outbound/orders', data);
}

export function updateOutbound(id, data) {
  return http.put(`/inventory/outbound/orders/${id}`, data);
}

export function deleteOutbound(id) {
  return http.delete(`/inventory/outbound/orders/${id}`);
}


export function updateOutboundStatus(id, status, data = {}) {
  const payload = { 
      status: String(status),
      ...data
  }; 
  console.log(`Updating outbound status for ID ${id} with payload:`, payload);
  return http.put(`/inventory/outbound/orders/${id}/status`, payload);
}


export function pickOutbound(id, data) {
  return http.post(`/inventory/outbound/orders/${id}/pick`, data);
}


export function shipOutbound(id, data) {
  return http.post(`/inventory/outbound/orders/${id}/ship`, data);
}
export function getPickingTasks() {
  return http.get('/inventory/outbound/picking-tasks');
}

export function getShippingTasks() {
  return http.get('/inventory/outbound/shipping-tasks');
}


export function getCustomerList(params) {
  return http.get('/customers', { params });
}


export function exportOutbound(params) {
  return http.get('/inventory/outbound/export', {
    params,
    responseType: 'blob'
  });
}

/**
 * 获取出库统计数据
 * 注意：后端尚未实现此API，前端使用本地计算方法
 */
export function getOutboundStatistics() {
  return http.get('/inventory/outbound/statistics');
}

export default {
  getOutboundList,
  getOutboundDetail,
  createOutbound,
  updateOutbound,
  deleteOutbound,
  updateOutboundStatus,
  pickOutbound,
  shipOutbound,
  getOutboundStatistics,
  exportOutbound,
}
